/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package flames.view;

import javax.swing.*;
import java.awt.*;
import java.util.Objects;

/**
 * @author 10373
 */
public class MenuDialog extends javax.swing.JDialog {

    public final Color ACTIVE_COLOR = new Color(242, 135, 24);    // #f28718
    public static final String ACCOUNT_IMG = "/flames/images/menu/bar_account.png";
    public static final String ACCOUNT_IMG_ACTIVE = "/flames/images/menu/bar_account_active.png";
    public static final String SETTING_IMG = "/flames/images/menu/bar_setting.png";
    public static final String SETTING_IMG_ACTIVE = "/flames/images/menu/bar_setting_active.png";
    public static final String UPDATE_IMG = "/flames/images/menu/bar_update.png";
    public static final String UPDATE_IMG_ACTIVE = "/flames/images/menu/bar_update_active.png";
    public static final String HELP_IMG = "/flames/images/menu/bar_help.png";
    public static final String HELP_IMG_ACTIVE = "/flames/images/menu/bar_help_active.png";
    public static final String ABOUT_IMG = "/flames/images/menu/bar_about.png";
    public static final String ABOUT_IMG_ACTIVE = "/flames/images/menu/bar_about_active.png";

    private Frame parent;

    /**
     * Creates new form MenuDialog
     */
    public MenuDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        this.parent = parent;   // 设置父组件
        this.setUndecorated(true); // 设置透明
        initComponents();
        // 美化下面的按钮
        setBtnBeauty(setting);
        setBtnBeauty(account);
        setBtnBeauty(update);
        setBtnBeauty(help);
        setBtnBeauty(about);
    }

    // 切换按钮样式和图片样式
    private void toggleBtnStyleAndImgStyle(JButton button, JLabel buttonImg, String activeUrl, String normalUrl) {
        if (button.isContentAreaFilled()) {
            button.setContentAreaFilled(false);
            button.setForeground(Color.BLACK);
            buttonImg.setIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource(normalUrl))));
        } else {
            button.setContentAreaFilled(true);
            button.setBackground(ACTIVE_COLOR);
            button.setForeground(Color.WHITE);
            buttonImg.setIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource(activeUrl))));
        }
    }

    // 切换字体样式
    private void toggleFontStyle(javax.swing.JButton button) {
        if (button.isContentAreaFilled()) {
            button.setForeground(Color.BLACK);
        } else {
            button.setForeground(Color.WHITE);
        }
    }

    // 切换图片
    private void toggleIcon(JButton button, JLabel buttonImg, String activeUrl, String normalUrl) {
        if (button.isContentAreaFilled()) {
            buttonImg.setIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource(normalUrl))));
        } else {
            buttonImg.setIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource(activeUrl))));
        }
    }

    // 美化按钮
    private void setBtnBeauty(JButton button) {
        button.setBorderPainted(false);
        button.setMargin(new Insets(0, 0, 0, 0));
        button.setContentAreaFilled(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLayeredPane1 = new javax.swing.JLayeredPane();
        BKG = new javax.swing.JLabel();
        Border1 = new javax.swing.JLabel();
        Border2 = new javax.swing.JLabel();
        Border3 = new javax.swing.JLabel();
        Border4 = new javax.swing.JLabel();
        settingImg = new javax.swing.JLabel();
        accountImg = new javax.swing.JLabel();
        updateImg = new javax.swing.JLabel();
        aboutImg = new javax.swing.JLabel();
        helpImg = new javax.swing.JLabel();
        setting = new javax.swing.JButton();
        account = new javax.swing.JButton();
        update = new javax.swing.JButton();
        about = new javax.swing.JButton();
        help = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(190, 250));
        addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                formMouseDragged(evt);
            }
        });
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                formMousePressed(evt);
            }
        });
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLayeredPane1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        BKG.setIcon(new javax.swing.ImageIcon(getClass().getResource("/flames/images/SecurityToolsPane/Security_Tools_BKG.png"))); // NOI18N
        BKG.setToolTipText("");
        BKG.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                BKGMouseDragged(evt);
            }
        });
        BKG.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                BKGMousePressed(evt);
            }
        });
        jLayeredPane1.add(BKG, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 190, 250));

        Border1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/flames/images/mainFrame/BorderYinYing.png"))); // NOI18N
        jLayeredPane1.add(Border1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 2, 250));

        Border2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/flames/images/mainFrame/BorderYinYing.png"))); // NOI18N
        jLayeredPane1.add(Border2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 190, 2));

        Border3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/flames/images/mainFrame/BorderYinYing.png"))); // NOI18N
        jLayeredPane1.add(Border3, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 250, 190, 2));

        Border4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/flames/images/mainFrame/BorderYinYing.png"))); // NOI18N
        jLayeredPane1.add(Border4, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 0, 2, 250));

        settingImg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/flames/images/menu/bar_setting.png"))); // NOI18N
        jLayeredPane1.setLayer(settingImg, javax.swing.JLayeredPane.MODAL_LAYER);
        jLayeredPane1.add(settingImg, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 60, 30));

        accountImg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/flames/images/menu/bar_account.png"))); // NOI18N
        jLayeredPane1.setLayer(accountImg, javax.swing.JLayeredPane.MODAL_LAYER);
        jLayeredPane1.add(accountImg, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 51, 70, 50));

        updateImg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/flames/images/menu/bar_update.png"))); // NOI18N
        jLayeredPane1.setLayer(updateImg, javax.swing.JLayeredPane.MODAL_LAYER);
        jLayeredPane1.add(updateImg, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 110, 60, 30));

        aboutImg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/flames/images/menu/bar_about.png"))); // NOI18N
        jLayeredPane1.setLayer(aboutImg, javax.swing.JLayeredPane.MODAL_LAYER);
        jLayeredPane1.add(aboutImg, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 198, 70, 50));

        helpImg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/flames/images/menu/bar_help.png"))); // NOI18N
        jLayeredPane1.setLayer(helpImg, javax.swing.JLayeredPane.MODAL_LAYER);
        jLayeredPane1.add(helpImg, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 150, 60, 50));

        setting.setFont(new java.awt.Font("新宋体", 0, 18)); // NOI18N
        setting.setText("安全设置");
        setting.setAlignmentY(0.0F);
        setting.setFocusPainted(false);
        setting.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                settingMouseEntered(evt);
            }

            public void mouseExited(java.awt.event.MouseEvent evt) {
                settingMouseExited(evt);
            }
        });
        setting.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                settingActionPerformed(evt);
            }
        });
        jLayeredPane1.setLayer(setting, javax.swing.JLayeredPane.PALETTE_LAYER);
        jLayeredPane1.add(setting, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 190, 50));

        account.setFont(new java.awt.Font("新宋体", 0, 19)); // NOI18N
        account.setText("用户登录");
        account.setAlignmentY(0.0F);
        account.setFocusPainted(false);
        account.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                accountMouseEntered(evt);
            }

            public void mouseExited(java.awt.event.MouseEvent evt) {
                accountMouseExited(evt);
            }
        });
        account.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                accountActionPerformed(evt);
            }
        });
        jLayeredPane1.setLayer(account, javax.swing.JLayeredPane.MODAL_LAYER);
        jLayeredPane1.add(account, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 50, 190, 50));

        update.setFont(new java.awt.Font("新宋体", 0, 19)); // NOI18N
        update.setText("检查更新");
        update.setAlignmentY(0.0F);
        update.setFocusPainted(false);
        update.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                updateMouseEntered(evt);
            }

            public void mouseExited(java.awt.event.MouseEvent evt) {
                updateMouseExited(evt);
            }
        });
        update.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateActionPerformed(evt);
            }
        });
        jLayeredPane1.setLayer(update, javax.swing.JLayeredPane.PALETTE_LAYER);
        jLayeredPane1.add(update, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 100, 190, 50));

        about.setFont(new java.awt.Font("新宋体", 0, 19)); // NOI18N
        about.setText("关于我们");
        about.setAlignmentY(0.0F);
        about.setFocusPainted(false);
        about.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                aboutMouseEntered(evt);
            }

            public void mouseExited(java.awt.event.MouseEvent evt) {
                aboutMouseExited(evt);
            }
        });
        about.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutActionPerformed(evt);
            }
        });
        jLayeredPane1.setLayer(about, javax.swing.JLayeredPane.PALETTE_LAYER);
        jLayeredPane1.add(about, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 200, 190, 50));

        help.setFont(new java.awt.Font("新宋体", 0, 19)); // NOI18N
        help.setText("帮助文档");
        help.setAlignmentY(0.0F);
        help.setFocusPainted(false);
        help.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                helpMouseEntered(evt);
            }

            public void mouseExited(java.awt.event.MouseEvent evt) {
                helpMouseExited(evt);
            }
        });
        help.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpActionPerformed(evt);
            }
        });
        jLayeredPane1.setLayer(help, javax.swing.JLayeredPane.PALETTE_LAYER);
        jLayeredPane1.add(help, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 150, 190, 50));

        getContentPane().add(jLayeredPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void settingMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_settingMouseEntered
        // 切换按钮样式和图片样式
        toggleBtnStyleAndImgStyle(setting, settingImg, SETTING_IMG_ACTIVE, SETTING_IMG);
    }//GEN-LAST:event_settingMouseEntered


    // 切换样式
    private void settingMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_settingMouseExited
        toggleBtnStyleAndImgStyle(setting, settingImg, SETTING_IMG_ACTIVE, SETTING_IMG);
    }//GEN-LAST:event_settingMouseExited

    // [设置中心] 点击之后会触发到这个方法
    private void settingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_settingActionPerformed
        SecuritySetting.runInstance();
    }//GEN-LAST:event_settingActionPerformed

    // 切换样式
    private void accountMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_accountMouseEntered
        toggleBtnStyleAndImgStyle(account, accountImg, ACCOUNT_IMG_ACTIVE, ACCOUNT_IMG);

    }//GEN-LAST:event_accountMouseEntered

    // 切换样式
    private void accountMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_accountMouseExited
        toggleBtnStyleAndImgStyle(account, accountImg, ACCOUNT_IMG_ACTIVE, ACCOUNT_IMG);
    }//GEN-LAST:event_accountMouseExited

    // 点击[用户登录]按钮将触发该方法
    private void accountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_accountActionPerformed
        Login.runInstance();
    }//GEN-LAST:event_accountActionPerformed

    // 切换样式
    private void updateMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_updateMouseEntered
        toggleBtnStyleAndImgStyle(update, updateImg, UPDATE_IMG_ACTIVE, UPDATE_IMG);
    }//GEN-LAST:event_updateMouseEntered

    // 切换样式
    private void updateMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_updateMouseExited
        toggleBtnStyleAndImgStyle(update, updateImg, UPDATE_IMG_ACTIVE, UPDATE_IMG);
    }//GEN-LAST:event_updateMouseExited

    // 点击[检查更新]按钮将触发该方法
    private void updateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateActionPerformed
        UpdateFrame.runInstance();
    }//GEN-LAST:event_updateActionPerformed

    // 使面板支持拖拽移动
    private void BKGMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_BKGMouseDragged
        formMouseDragged(evt);
    }//GEN-LAST:event_BKGMouseDragged

    // 使面板支持拖拽移动
    private void BKGMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_BKGMousePressed
        formMousePressed(evt);
    }//GEN-LAST:event_BKGMousePressed

    private void formMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMousePressed

    }//GEN-LAST:event_formMousePressed

    private void formMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseDragged

    }//GEN-LAST:event_formMouseDragged

    // 切换样式
    private void helpMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_helpMouseEntered
        toggleBtnStyleAndImgStyle(help, helpImg, HELP_IMG_ACTIVE, HELP_IMG);
    }//GEN-LAST:event_helpMouseEntered

    // 切换样式
    private void helpMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_helpMouseExited
        toggleBtnStyleAndImgStyle(help, helpImg, HELP_IMG_ACTIVE, HELP_IMG);
    }//GEN-LAST:event_helpMouseExited

    // 点击[帮助文档]按钮将触发该方法
    private void helpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpActionPerformed
        Runtime rt = Runtime.getRuntime();
        try {
            // 用Windows的hh.exe应用打开 帮助文档
            rt.exec("hh.exe " + "help.chm");
        } catch (java.io.IOException ex) {
            javax.swing.JOptionPane.showMessageDialog(rootPane, ex);
        }
    }//GEN-LAST:event_helpActionPerformed

    // 切换样式
    private void aboutMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_aboutMouseEntered
        toggleBtnStyleAndImgStyle(about, aboutImg, ABOUT_IMG_ACTIVE, ABOUT_IMG);
    }//GEN-LAST:event_aboutMouseEntered

    // 切换样式
    private void aboutMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_aboutMouseExited
        toggleBtnStyleAndImgStyle(about, aboutImg, ABOUT_IMG_ACTIVE, ABOUT_IMG);
    }//GEN-LAST:event_aboutMouseExited

    // 点击[关于我们]按钮将触发该方法
    private void aboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutActionPerformed
        AboutFrame.runInstance();
    }//GEN-LAST:event_aboutActionPerformed

    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        /* Set the Nimbus look and feel */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
//         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(MenuDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(MenuDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(MenuDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(MenuDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        /* Create and display the dialog */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                MenuDialog dialog = new MenuDialog(new javax.swing.JFrame(), true);
//                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
//                    @Override
//                    public void windowClosing(java.awt.event.WindowEvent e) {
//                        System.exit(0);
//                    }
//                });
//                dialog.setVisible(true);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel BKG;
    private javax.swing.JLabel Border1;
    private javax.swing.JLabel Border2;
    private javax.swing.JLabel Border3;
    private javax.swing.JLabel Border4;
    private javax.swing.JButton about;
    private javax.swing.JLabel aboutImg;
    private javax.swing.JButton account;
    private javax.swing.JLabel accountImg;
    private javax.swing.JButton help;
    private javax.swing.JLabel helpImg;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JButton setting;
    private javax.swing.JLabel settingImg;
    private javax.swing.JButton update;
    private javax.swing.JLabel updateImg;
    // End of variables declaration//GEN-END:variables
}
